package com.charity.service;

import com.charity.model.bo.CharityAddDonationInputBO;
import com.charity.model.bo.CharityAddEntrydInputBO;
import com.charity.model.bo.CharityDeleteDonationInputBO;
import com.charity.model.bo.CharityDeleteEntry_dInputBO;
import com.charity.model.bo.CharitySearchDonationBydonoridInputBO;
import com.charity.model.bo.CharitySearchDonationByidInputBO;
import com.charity.model.bo.CharityUpdateDonationInputBO;
import com.charity.model.bo.CharityUpdateEntryTobuchongInputBO;
import com.charity.model.bo.CharityUpdateEntryTocolInputBO;
import com.charity.model.bo.CharityUpdateEntryTofafanInputBO;
import com.charity.model.bo.CharityUpdateEntry_dInputBO;
import java.lang.Exception;
import java.lang.String;
import java.util.Arrays;
import javax.annotation.PostConstruct;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.fisco.bcos.sdk.client.Client;
import org.fisco.bcos.sdk.transaction.manager.AssembleTransactionProcessor;
import org.fisco.bcos.sdk.transaction.manager.TransactionProcessorFactory;
import org.fisco.bcos.sdk.transaction.model.dto.CallResponse;
import org.fisco.bcos.sdk.transaction.model.dto.TransactionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
@NoArgsConstructor
@Data
public class CharityService {
  public static final String ABI = com.charity.utils.IOUtil.readResourceAsString("abi/Charity.abi");

  public static final String BINARY = com.charity.utils.IOUtil.readResourceAsString("bin/ecc/Charity.bin");

  public static final String SM_BINARY = com.charity.utils.IOUtil.readResourceAsString("bin/sm/Charity.bin");

  @Value("${system.contract.charityAddress}")
  private String address;

  @Autowired
  private Client client;

  AssembleTransactionProcessor txProcessor;

  @PostConstruct
  public void init() throws Exception {
    this.txProcessor = TransactionProcessorFactory.createAssembleTransactionProcessor(this.client, this.client.getCryptoSuite().getCryptoKeyPair());
  }

  public TransactionResponse addEntryd(CharityAddEntrydInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "addEntryd", input.toArgs());
  }

  public CallResponse _key2() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "_key2", Arrays.asList());
  }

  public TransactionResponse updateEntryTofafan(CharityUpdateEntryTofafanInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateEntryTofafan", input.toArgs());
  }

  public TransactionResponse updateEntryTobuchong(CharityUpdateEntryTobuchongInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateEntryTobuchong", input.toArgs());
  }

  public TransactionResponse addDonation(CharityAddDonationInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "addDonation", input.toArgs());
  }

  public CallResponse searchDonationBydonorid(CharitySearchDonationBydonoridInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "searchDonationBydonorid", input.toArgs());
  }

  public CallResponse searchAllDonation() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "searchAllDonation", Arrays.asList());
  }

  public TransactionResponse deleteEntry_d(CharityDeleteEntry_dInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "deleteEntry_d", input.toArgs());
  }

  public TransactionResponse updateEntry_d(CharityUpdateEntry_dInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateEntry_d", input.toArgs());
  }

  public TransactionResponse updateEntryTocol(CharityUpdateEntryTocolInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateEntryTocol", input.toArgs());
  }

  public TransactionResponse deleteDonation(CharityDeleteDonationInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "deleteDonation", input.toArgs());
  }

  public TransactionResponse updateDonation(CharityUpdateDonationInputBO input) throws Exception {
    return this.txProcessor.sendTransactionAndGetResponse(this.address, ABI, "updateDonation", input.toArgs());
  }

  public CallResponse searchDonationByid(CharitySearchDonationByidInputBO input) throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "searchDonationByid", input.toArgs());
  }

  public CallResponse _key1() throws Exception {
    return this.txProcessor.sendCall(this.client.getCryptoSuite().getCryptoKeyPair().getAddress(), this.address, ABI, "_key1", Arrays.asList());
  }
}
